package com.gym.openapi.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gym.openapi.common.ResponseResult;
import com.gym.openapi.common.ResultTable;
import com.gym.openapi.dao.AppInfoMapper;
import com.gym.openapi.entity.AppInfo;
import com.gym.openapi.services.AppInfoServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ming
 * 2021/11/26
 * description:应用管理
 */
@Service
public class AppInfoServicesImpl implements AppInfoServices {
    @Autowired
    private AppInfoMapper appInfoMapper;


    @Override
    public ResultTable appTable(Integer page, Integer limit, String corpName) {
        PageHelper.startPage(page, limit);
        List<AppInfo> la = appInfoMapper.appTable(corpName);
        PageInfo<AppInfo> pa = new PageInfo(la);
        return new ResultTable(0,"", (int) pa.getTotal(),pa.getList());
    }

    @Override
    public ResponseResult  del(Integer[] ids) {
        int i = appInfoMapper.del(ids);
        if (i>0) {
            return ResponseResult.getSuccess("应用删除成功");
        }
        return ResponseResult.getFail("删除失败");
    }

    @Override
    public ResponseResult update(AppInfo appInfo1) {
        if (appInfo1!=null) {
            int i = appInfoMapper.updateByPrimaryKeySelective(appInfo1);
            if (i>0) {
                return ResponseResult.getSuccess();
            }
        }
        return ResponseResult.getFail("fail");

    }

    @Override
    public ResponseResult add(AppInfo appInfo2) {
        if (appInfo2!=null) {
            int i = appInfoMapper.insertSelective(appInfo2);
            if (i>0) {
                return ResponseResult.getSuccess("jiahoal ");
            }
        }
        return ResponseResult.getFail("添加失败哦");
    }
}
